package com.hongxun.design.utils.maputil;

import android.content.Context;

import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.geocode.GeoCodeOption;
import com.baidu.mapapi.search.geocode.GeoCoder;
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeOption;
import com.hongxun.design.bean.Exploration;


/**
 * Created by zerdoor_pc on 2016/5/4.
 */
public class GeoCodeUtil {

    private static GeoCodeUtil instence;
    GeoCoder mSearch = null; // 搜索模块，也可去掉地图模块独立使用
    Context context;
    GeoCodeUtil(Context context){
        this.context=context;
        mSearch = GeoCoder.newInstance();
        mSearch.setOnGetGeoCodeResultListener((OnGetGeoCoderResultListener) context);
    }

    public static GeoCodeUtil getInstence(Context context){
        if (instence==null){
            instence=new GeoCodeUtil(context);
        }
        return instence;
    }

    public void LatLngToAdress(LatLng ptCenter){
        if (mSearch==null)return;
        try {

            mSearch.reverseGeoCode(new ReverseGeoCodeOption()
                    .location(ptCenter));
        }catch (Exception e){}
    }

    public void AdressToLatLng(String City,String Adress){
        // Geo搜索
        mSearch.geocode(new GeoCodeOption().city(
                City).address(Adress));
    }


    public void onDestroy() {
        instence=null;
        mSearch.destroy();

    }


}
